<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="StyleSheet" href="../css/jpetstore.css" type="text/css" media="screen"/>
</head>
<body>
<header th:replace="common/top"></header>
<div id="Content">
    <div id="BackLink">
        <a href="/catalog/viewmain">Return to Main Menu</a>
    </div>

    <div id="Catalog">
        <div id="Cart">
            <h2>Shopping Cart</h2>
            <form action="/cart/updateCartQuantities" method="post">
                <table>
                    <tr>
                        <th><b>Item ID</b></th>
                        <th><b>Product ID</b></th>
                        <th><b>Description</b></th>
                        <th><b>In Stock?</b></th>
                        <th><b>Quantity</b></th>
                        <th><b>List Price</b></th>
                        <th><b>Total Cost</b></th>
                        <th>&nbsp;</th>
                    </tr>
                    <tr th:if="${cart.numberOfItems == 0}">
                        <td colspan="8"><b>Your cart is empty.</b></td>
                    </tr>

                    <tr th:each="cartItem:${cart.cartItems}">
                        <td>
                            <a th:href="'/category/viewItem?itemId='+${cartItem.item.itemId}" th:text="${cartItem.item.itemId}"></a>
                        </td>
                        <td th:text="${cartItem.item.product.productId}"></td>
                        <td th:text="${cartItem.item.attribute1}+${cartItem.item.product.name}"></td>
                        <td th:text="${cartItem.inStock}"></td>
                        <td>
                            <input type="text" th:name="${cartItem.item.itemId}" th:value="${cartItem.quantity}">
                        </td>
                        <td th:text="'$'+${#numbers.formatDecimal(cartItem.item.listPrice,1,2)}"></td>
                        <td th:text="'$'+${#numbers.formatDecimal(cartItem.total,1,2)}"></td>
                        <td>
                            <a class="Button" th:href="'/cart/removeItemFromCart?workingItemId='+${cartItem.item.itemId}">Remove</a>
                        </td>
                    </tr>

                    <tr>
                        <td colspan="7">
                            <label th:text="'Sub Total:$'+${#numbers.formatDecimal(cart.subTotal,1,2)}"></label>
                            <input type="submit" value="Update Cart">
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </form>

            <a class="Button" th:if="${cart.numberOfItems > 0}" href="/cart/order">
                Proceed to Checkout
            </a>
        </div>
        <div id="MyList" th:if="(${session.account} != null) and (${session.authenticated})">
            <div th:if="${session.account.listOption}">
                <p>Pet Favorites <br />
                    Shop for more of your favorite pets here.
                </p>
                <ul>
                    <li th:each="product:${session.myList}">
                        <a th:href="'/category/viewProduct?productId='+${product.productId}" th:text="${product.productId}"></a>
                    </li>
                </ul>
            </div>
        </div>
        <div id="Separator">&nbsp;</div>
    </div>

</div>
<footer th:replace="common/bottom"></footer>
</body>
</html>